package nx.simple3d.data.worker;

import java.util.concurrent.Semaphore;

import nx.simple3d.data.Camera;
import nx.simple3d.data.Mesh;
import nx.simple3d.data.VectorBase;
import nx.simple3d.data.World;

public class ProjectionWorker implements Runnable{
  
  private boolean isRunning = true;
  private Camera camera;
  private World world;
  private Semaphore vectorBaseSemaphore;
  
  public ProjectionWorker(World world){
    this.world = world;
    camera = world.getCamera();
    vectorBaseSemaphore = VectorBase.getInstance().getSemaphore();
  }
  
  public void run() {
    while(isRunning) {
      try {
        vectorBaseSemaphore.acquire();
        for(Mesh mesh : world.getMeshes()){
          camera.project(mesh);
        }
      }
      catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    isRunning = true;
  }
  
  public void stop(){
    isRunning = false;
  }
} 
